import pandas as pd

from bct.tools.client.bct4_client import BCT4Client
from bct_config import Bct4Hoster

include_vanilla_product_type = [
    "VANILLA_AMERICAN", "VANILLA_EUROPEAN",
    "EAGLE",
    "VANILLA_LIMIT_RANGE_PROTECTIVE", "VANILLA_RANGE_PROTECTIVE_VERTICAL_SPREAD",
    "VANILLA_LIMIT_RANGE_PROTECTIVE_VERTICAL_SPREAD", "VANILLA_RANGE_PROTECTIVE",
    "STRADDLE",
    "VANILLA_PARTICIPATION_CALL", "VERTICAL_SPREAD"]

include_knock_out_product_type = ["EAGLE", "SHARK_FIN", "DOUBLE_SHARK_FIN",
                                  "RANGE_ENHANCE", "SNOWBALL_AUTO_REDEEM_SPREAD_CALL"]

include_knock_in_product_type = ["KNOCK_IN_DOWN_CALL", "KNOCK_IN_DOWN_PUT"]

include_airbag_product_type = ["AIRBAG_VANILLA", "AIRBAG_SPREAD", "AIRBAG_PROTECTIVE", "AIRBAG_SPREAD_PROTECTIVE"]

include_range_accruals_product_type = ["RANGE_ACCRUALS_DIGITAL_PUT", "RANGE_ACCRUALS_DIGITAL_CALL", "RANGE_ACCRUALS"]

if __name__ == '__main__':
    # 清除某个交易簿的交易

    # book_name = '场外期权'
    print("开始清除交易")
    df = pd.read_excel('trade_clean.xlsx', sheet_name='Sheet1')
    trade_ids = []
    for d in df['交易编号']:
        if len(d) > 0:
            trade_ids.append(d)
    config = Bct4Hoster()
    client = BCT4Client(config.host, config.script_user, config.script_pwd)
    total_trade = len(trade_ids)
    if total_trade > 0:
        counter = 0
        for trade_id in trade_ids:
            try:
                client.delete_trade(trade_id)
            except Exception as e:
                print(e)
            counter += 1
            print("%s deleted %s/%s" % (trade_id, counter, total_trade))
        print("%s deleted" % total_trade)
    else:
        print("no trade to delete")
